package org.yzh.web.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.yzh.protocol.t808.T0200;
import org.yzh.web.mapper.LocationMapper;
import org.yzh.web.entity.Jt808;
import org.yzh.web.vo.LocationVo;
import org.yzh.web.service.locationService;
import org.yzh.web.vo.ResponseVo;
import org.yzh.web.vo.TrackVo;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class locationServiceImpl  implements locationService {

    @Resource
    LocationMapper locationMapper;

    @Override
    public void insert(List<T0200> list) {
        Jt808 jt808 = new Jt808();

        List<Jt808> collect = list.stream().map(item -> {
            BeanUtils.copyProperties(item, jt808);
            LocalDateTime currentDateTime = LocalDateTime.now();
            jt808.setGmtCreate(currentDateTime);
            jt808.setGmtModified(currentDateTime);
            return jt808;
        }).collect(Collectors.toList());

        locationMapper.insert(collect);
    }
    @Override
        public List<TrackVo> queryTrack(LocationVo vo) {
        int pageNum = vo.getPageNum();
        int pageSize = vo.getPageSize();
        List<TrackVo> rvo = new ArrayList<>();
        PageHelper.startPage(pageNum,pageSize);
        rvo = locationMapper.queryTrack(vo);

        return rvo;
    }
}
